package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.pudao.*;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 朴道—黑卡定制
 *
 * @author xj
 */

public class PuDaoCustomerLabelRecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 朴道—黑卡定制
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        PuDaoCustomerLabelRecord obj = (PuDaoCustomerLabelRecord) model;
        PuDaoCustomerLabelData data = obj.getData() == null ? new PuDaoCustomerLabelData() : obj.getData();
        PuDaoCustomerLabel info = data.getData() == null ? new PuDaoCustomerLabel() : data.getData();

        StringBuilder sb = getBaseInfo(obj, successful);
        //首次使用距今时长
        sb.append(info.getLargeConsumerUsr()).append(CRT001);
        //最后使用是否在180天内
        sb.append(info.getStagingTendencyUsr()).append(CRT001);
        //最后使用是否在30天内
        sb.append(info.getPotentialCreditCardUsr()).append(CRT001);
        //最后使用是否在30-90天内
        sb.append(info.getPotentialLendingUsr()).append(CRT001);
        //最后使用是否在90-180天内
        sb.append(info.getHighQualityUsr()).append(CRT001);
        //是否常用手机号
        sb.append(info.getTotDlqDaysAll90Level()).append(CRT001);
        key.set(getKey());
        val.set((sb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_pu_dao_customer_label_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.PD_CUSTOMER_LABEL_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "朴道—黑卡定制";
    }
}
